# 外观数列问题。这种问题一般根据n-1推出n的一般思路就是通过迭代和递归解决问题

# 递归解决
def countAndSay(self, n: int) -> str:
    # 这种问题一般不是递归就是迭代
    if n == 1: return '1'
    temp = self.countAndSay(n - 1)
    res = ''  # 结果
    count = 1
    for i in range(1, len(temp)):
        if temp[i] != temp[i - 1]:
            res = res + str(count) + temp[i - 1]
            count = 1
        else:
            count = count + 1
    return res + str(count) + temp[len(temp) - 1]


# 迭代解决问题
def countAndSay(self, n: int) -> str:
    # 迭代
    i = 1
    res = "1"
    while i < n:
        i = i + 1
        count = 1
        tempStr = ''
        for j in range(1, len(res)):
            if res[j] != res[j - 1]:
                tempStr = tempStr + str(count) + res[j - 1]
                count = 1
            else:
                count = count + 1
        tempStr = tempStr + str(count) + res[len(res) - 1]
        res = tempStr
    return res

'''
迭代和递归就是一个从小变大(迭代), 一个从大变小(递归)
'''